package com.iespring.exception;

import com.iespring.bean.common.BaseRespVo;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ExceptionControllerAdvise {

    @ExceptionHandler(AuthorizationException.class)
    public BaseRespVo handlerAuthorException(AuthorizationException e) {
        String message = e.getMessage();
        return BaseRespVo.noPermission();
    }

    @ExceptionHandler(InvalidParamException.class)
    public BaseRespVo invalidParamException(InvalidParamException e) {
        return BaseRespVo.invalidParameter(e.getMessage());
    }

    /**
     * 非法数据异常
     *
     * @since 2022/12/30 22:37
     */
    @ExceptionHandler(InvalidDataException.class)
    public BaseRespVo invalidDataException(InvalidDataException e) {
        return BaseRespVo.invalidData(e.getMessage());
    }

    @ExceptionHandler(UnknownAccountException.class)
    public BaseRespVo unknownAccountException(UnknownAccountException e) {
        return BaseRespVo.unAccount("账号不存在-_-||");
    }
    @ExceptionHandler(IncorrectCredentialsException.class)
    public BaseRespVo incorrectCredentialsException(IncorrectCredentialsException e){
        return BaseRespVo.unAccount("密码不正确-_-||");
    }
}
